const autoprefixer = require('autoprefixer');
const pxtorem = require('postcss-pxtorem');
const path = require('path');
const CompressionWebpackPlugin = require('compression-webpack-plugin');
const productionGzipExtensions = ['js', 'css'];


function resolve(dir) {
  return path.join(__dirname, dir)
}
const Timestamp = new Date().getTime();
module.exports = {
  lintOnSave: true,
  outputDir: 'dist',
  publicPath: '/',
  css: {
    loaderOptions: {
      postcss: {
        plugins: [
          autoprefixer(),
          pxtorem({
            rootValue: 56,
            propList: ['*']
          })
        ]
      }
    }
  },
  devServer: {
    host: '0.0.0.0',
    port: 8001,
    proxy: {
      '/mock': {
        target: 'https://www.easy-mock.com/mock/5d6c9459cb03594446dd4d3c/yyz',
        ws: true,
        changeOrigin: true,
        pathRewrite: {
          '^/mock': ''
        }
      }
    }
  },
  configureWebpack: {
    plugins: [
      new CompressionWebpackPlugin({
        algorithm: 'gzip',
        test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
        threshold: 10240,
        minRatio: 0.8
      })
    ],
    output: { // js添加时间戳
      filename: `js/[name].${Timestamp}.js`,
      chunkFilename: `js/[name].${Timestamp}.js`,
    },
    // extract: {//css添加时间戳
    //   filename: `css/[name].${Timestamp}.css`,
    //   chunkFilename: `css/[name].${Timestamp}.css`,
    // },
    // output: { // 输出重构  打包编译后的 文件名称  【模块名称.版本号.时间戳】
    //   chunkFilename: `[name].${Timestamp}.js`
    // },
    resolve: {
      alias: {
        '@a': resolve('src/asset'),
        '@c': resolve('src/components'),
        '@p': resolve('public')
      }
    }
  }
};

